/*
 * Created on 26/Dez/2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package ceirinhashls.util;

/**
 * @author botelhodaniel
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class XMLUtil {
	
	public static String validateXML(String str){
		str = str.replaceAll("&","&amp;");
		str = str.replaceAll("<","&lt;");
		str = str.replaceAll(">","&gt;");
		str = str.replaceAll("'","&apos;");
		str = str.replaceAll("\"","&quot;");
		return str;
	}
	
	public static String XMLToString(String str){
		str = str.replaceAll("&quot;","\"");
		str = str.replaceAll("&apos;","'");
		str = str.replaceAll("&gt;",">");
		str = str.replaceAll("&lt;","<");
		str = str.replaceAll("&amp;","&");
		return str;
	}
	
	public static void main(String[] args) {
		String s;
		s=validateXML("<sd & 'comer \"sde\">");
		System.out.println(s);
		System.out.println(XMLToString(s));
		//& 'comer \"sde\"
	}
}
